package com.ibm.cps.sql.expression.function.vector;

public class VarianceDescriptor implements VectorFunctionDescriptor {


	@Override
	public Double[] evaluate(Double[] input) {
		double sum = 0;
		double squareSum = 0;
		for (int i = 2; i < input.length; i++) {
			double value = ((Number) input[i]).doubleValue();
			sum += value;
			squareSum += value * value;
		}
		double avg = sum / (input.length - 2);
		double variance = squareSum / (input.length - 2) - avg * avg;
		return new Double[]{variance};
	}

	@Override
	public boolean isArray() {
		return false;
	}

}
